package state;

public class State {

	public static final State IDLE = new State(0);
	public static final State IN_PAUSE = new State(1);
	public static final State PAGE_SELECTION = new State(2);
	
	private int value;
	
	private State(int aValue) {
		value = aValue;
	}
	
	public State(State[] states) {
		int value = 0;
		
		for (int i = 0; i < states.length; i++) {
			value = value | states[i].getValue();
		}
	}
	
	public State(State aState) {
		this(aState.getValue());
	}

	public void add(State newState) {
		value = value | newState.getValue();
	}
	
	public void remove(State newState) {
		value = value - (value & newState.getValue());
	}
	
	public boolean equals(State aState) {
		return (aState.getValue() & value) > 0;
	}

	private int getValue() {
		return value;
	}
	
	public void flip(State aState) {
		if (this.equals(aState)) {
			this.remove(aState);
		} else {
			this.add(aState);
		}
	}
}
